package com.jsoft.model;

import com.jsoft.dto.RecipeDto;
import com.jsoft.model.core.BaseDao;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * Date: 05.09.13
 * Time: 9:36
 */

@Entity
@Table(name = "recipes")
public class RecipeDao extends BaseDao {
    @Column(name = "name")
    private String name;
    @Column(name = "price")
    private BigDecimal price;   //Себестоимость
    @ManyToMany
    @JoinTable(name = "recipe_product",
            joinColumns = @JoinColumn(name = "recipe_id"),
            inverseJoinColumns = @JoinColumn(name = "product_id")
    )
    private List<ProductDao> productList;
    @Column(name = "barcode")
    private Integer barcode;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    private RecipeDao parentRecipe;
    @OneToMany(mappedBy = "parentRecipe")
    private List<RecipeDao> recipeList;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public List<ProductDao> getProductList() {
        return productList;
    }

    public void setProductList(List<ProductDao> productList) {
        this.productList = productList;
    }

    public Integer getBarcode() {
        return barcode;
    }

    public void setBarcode(Integer barcode) {
        this.barcode = barcode;
    }

    public RecipeDao getParentRecipe() {
        return parentRecipe;
    }

    public void setParentRecipe(RecipeDao parentRecipe) {
        this.parentRecipe = parentRecipe;
    }

    public List<RecipeDao> getRecipeList() {
        return recipeList;
    }

    public void setRecipeList(List<RecipeDao> recipeList) {
        this.recipeList = recipeList;
    }

    public RecipeDto wrapRecipeDto() {
        RecipeDto dto = new RecipeDto();
        dto.setId(this.getObjectId());
        dto.setName(this.getName());
        dto.setPrice(this.getPrice());
        return dto;
    }

    public RecipeDao wrapRecipeDao(RecipeDto dto) {
        RecipeDao dao = new RecipeDao();
        dao.setName(dto.getName());
        dao.setPrice(dto.getPrice());
        return dao;
    }
}